package cn.gavin.web.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

// 登录拦截器
public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        Object employee = request.getSession().getAttribute("USER_IN_SESSION"); // 从 session 获取用户信息
        if (employee == null){
            response.sendRedirect("/login.html");
            return false; // 不放行
        }
        return true; // 放行
    }
}
